<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <!-- header -->
    <%@ include file="/WEB-INF/views/include/header.jsp" %>
    <%--多附件上传css--%>
    <link rel="stylesheet" href="<s:url value="/assets/css/main.css"></s:url>"/>
</head>
<body class="no-skin">
<%--上传成功模态框--%>
<div class="shade" style="display: none;"></div>
<div class="warning" style="display: none;">
    <p class="title"><em></em><span class="close">X</span></p>
    <p class="cont"></p>
    <div class="la-square-jelly-box la-3x">
        <div></div>
        <div></div>
    </div>
</div>
<div class="modal fade" id="UrgeModel" tabindex="-1" role="dialog"  aria-hidden="true"
     data-backdrop="static">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">催办</h4> </div>
            <div class="modal-body ">
                <div class="information">
                    <div class="form-group clearfix">
                        <label class="control-label col-sm-2 text-right">姓名</label>
                        <div class="col-sm-9">
                            <input type="text" class="Modelname form-control" readonly >
                        </div>
                    </div>
                    <div class="form-group clearfix">
                        <label class="control-label col-sm-2 text-right">电话</label>
                        <div class="col-sm-9">
                            <input type="text" class="Modelphone form-control" readonly >
                        </div>
                    </div>
                </div>
                <div class="form-group clearfix">
                    <div class="col-sm-offset-2 col-sm-6">
                        <input type="checkbox" value="1" name="type">推送主要领导
                    </div>
                </div>
                <div class="form-group clearfix">
                    <label class="control-label col-sm-2 text-right">常用语句</label>
                    <div class="col-sm-9">
                        <select class="form-control">
                            <option value="">点击选择</option>
                            <option>速度办理</option>
                            <option>及时办理</option>
                        </select>
                    </div>
                </div>
                <div class="form-group clearfix">
                    <label class="control-label col-sm-2 text-right">催办内容</label>
                    <div class="col-sm-9">
                        <textarea rows="3" class="form-control" style="resize: vertical;min-height: 100px"></textarea>
                    </div>
                </div>

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-success UrgeSure" data-dismiss="modal">确定</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
<div class="modal fade" id="approval" tabindex="-1" role="dialog" aria-hidden="true"
     data-backdrop="static">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">审批</h4> </div>
            <div class="modal-body ">
                <div class="information1">
                    <div class="form-group clearfix">
                        <label class="control-label col-sm-2 text-right">任务名称</label>
                        <div class="col-sm-9">
                            <input type="text" class="mainName form-control" readonly value="">
                        </div>
                    </div>
                    <div class="form-group clearfix">
                        <label class="control-label col-sm-2 text-right">内容</label>
                        <div class="col-sm-9">
                            <textarea type="text" class="Modelcontent form-control" readonly ></textarea>
                        </div>
                    </div>
                    <div class="form-group clearfix">
                        <div class="col-sm-9 col-sm-offset-2">
                            <input type="radio" name="isApproval" value="2">通过
                            <input type="radio" name="isApproval" value="1">不通过
                        </div>
                    </div>
                    <div class="form-group clearfix">
                        <label class="control-label col-sm-2 text-right">审批意见</label>
                        <div class="col-sm-9">
                            <textarea rows="3" class="form-control content"></textarea>
                        </div>
                        <input type="hidden" class="taskMain" taskMain="${taskMain.sysId}">
                        <input type="hidden" class="sysId" value="">
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-success addApproval" data-dismiss="modal">确定</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
<%--修改--%>
<div class="modal fade" id="modify" tabindex="-1" role="dialog"  aria-hidden="true"
     data-backdrop="static">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">修改</h4> </div>
            <div class="modal-body ">
                <%--时限 类型--%>
                <div class="form-group clearfix">
                    <label class="control-label col-sm-2 text-right">任务时限</label>
                    <div class="col-sm-9">
                        <input type="text" readonly lay-verify="date" placeholder="年-月-日" autocomplete="off" class="form-control date_picker" name="getTimeLimit" readonly>
                    </div>
                </div>
                <input type="hidden" name="sysId">
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-success confirmModify" data-dismiss="modal">确定</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>


<!-- /section:basics/navbar.layout -->
<div class="main-container" id="main-container">
    <%--多附件上传的name和id--%>

    <input type="text" name="file" value=""  hidden>
    <input type="text" name="fileName" value="" hidden>

    <!-- /section:basics/sidebar -->
    <div class="main-content">
        <div class="main-content-inner">
            <div class="page-content">
                <!-- /section:settings.box -->
                <h3 class="text-center">我派发的任务</h3>
                <div id="taskMainId" style="display: none">
                    ${taskMainId}
                </div>
                <div class="form-group clearfix">
                    <h3 class="text-left">
                        任务名称:${taskMain.taskName}
                    </h3>
                </div>
                <div class="form-group clearfix">
                    <c:if test="${not empty taskMain.taskCont}">
                    <h4 class="text-left">
                        任务内容:${taskMain.taskCont}
                    </h4>
                    </c:if>
                </div>

                <div class="form-group clearfix">
                    <c:if test="${not empty taskMain.files}">
                    <h4 class="col-sm-1">
                        附件:
                    </h4>
                    <div class="col-sm-9">
                        <%--<input type="text" disabled value="${taskMain.fileName}"><button class="btn-success btn-sm" FileSysId="${taskMain.file}" onclick="download(this)" style="margin-left: 10px">下载附件</button>--%>
                            <c:if test="${not empty taskMain.files}">
                                <c:forEach items="${taskMain.files}" var="fileMap">
                                    <div style="margin-bottom:15px;">
                                        <input style="width: 50%;" type="text" class="fileName" readonly
                                               title="${fileMap.fileName}"
                                               value="${fileMap.fileName}" onclick="copyFile(this)">
                                        <button class="btn btn-primary file" onclick="download(this)"
                                                FileSysId="${fileMap.file}">
                                            下载附件
                                        </button>
                                    </div>
                                </c:forEach>
                            </c:if>
                            <c:if test="${empty taskMain.files}">
                                <input style="width: 50%;" type="text" value="无附件" class=" col-sm-3 form-control" readonly>
                            </c:if>
                    </div>
                    </c:if>
                </div>


<%--
                <c:if test="${taskMain.categoryId == '20190919100000000001'}">
                    <c:choose>
                        &lt;%&ndash;读&ndash;%&gt;
                        <c:when test="${dept.deptRelation == '/01/'}">
                            <div class="form-group clearfix">
                                <div>
                                    <label class="col-sm-1 control-label">督办单位反馈:</label>
                                    <div class="col-sm-9">
                                        <textarea rows="1" class="form-control FeedbackContent"  placeholder="请输入内容" readonly style="resize: vertical;min-height: 50px;">${taskMain.mainResult}</textarea>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group clearfix">
                                <label class="control-label col-sm-1">反馈附件:</label>
                                <div class="col-sm-8">
                                    &lt;%&ndash;    &lt;%&ndash;下载&ndash;%&gt;
                                    <input type="text" readonly value="${taskMain.mainResultFileName}">
                                    <button class="btn btn-info" onclick="download(this)" FileSysId = "${taskMain.mainResultFile}">
                                        下载附件
                                    </button>&ndash;%&gt;
                                        <c:if test="${not empty taskMain.mainResultFile}">
                                            <c:forEach items="${taskMain.mainResultFile}" var="fileMap">
                                                <div style="margin-bottom:15px;">
                                                    <input style="width: 50%;" type="text" class="fileName" readonly
                                                           title="${fileMap.fileName}"
                                                           value="${fileMap.fileName}" onclick="copyFile(this)">
                                                    <button class="btn btn-primary file" onclick="download(this)"
                                                            FileSysId="${fileMap.file}">
                                                        下载附件
                                                    </button>
                                                </div>
                                            </c:forEach>
                                        </c:if>
                                        <c:if test="${empty taskMain.mainResultFile}">
                                            <input style="width: 50%;" type="text" value="无附件" class=" col-sm-3 form-control" readonly>
                                        </c:if>
                                </div>
                            </div>
                            <c:if test="${taskMain.status != '4'}">
                                <div class="form-group clearfix">
                                    <label class="control-label col-sm-1">是否办结:</label>
                                    <div class="col-sm-8">
                                        <button onclick="taskTtatus(4)" class="btn-sm btn btn-success">办结</button>
                                        <button onclick="taskTtatus(5)" class="btn btn-sm btn-danger">退回重办</button>
                                    </div>
                                </div>
                            </c:if>
                            <c:if test="${taskMain.status == '4'}">
                                <div class="form-group clearfix">
                                    <label class="control-label col-sm-1">评价:</label>
                                    <div class="col-sm-2 yc">
                                        <select class="form-control hg"  id ="task-evaluations">
                                            <option value="1">好</option>
                                            <option value="2">中</option>
                                            <option value="2">差</option>
                                        </select>
                                    </div>
                                    <button onclick="evaluations()" class="btn-sm btn btn-success">确认评价</button>
                                </div>
                            </c:if>
                        </c:when>
                        &lt;%&ndash;写&ndash;%&gt;
                        <c:when test="${dept.sysId == taskMain.overdueDept and roleId == '02'}">
                            <div class="form-group clearfix">
                                <div>
                                    <label class="col-sm-1 control-label">单位重大反馈:</label>
                                    <div class="col-sm-9">
                                        <textarea rows="1" class="form-control"  name="mainResult" placeholder="请输入内容" style="resize: vertical;min-height: 50px;">${taskMain.mainResult}</textarea>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group clearfix">
                                <label class="control-label col-sm-1">单位反馈附件:</label>
                                <div class="col-sm-8">
                                    <c:if test="${not empty taskMain.mainResultFile}">
                                        <c:forEach items="${taskMain.mainResultFile}" var="fileMap">
                                            <div style="margin-bottom:15px;">
                                                <input style="width: 50%;" type="text" class="fileName" readonly
                                                       title="${fileMap.fileName}"
                                                       value="${fileMap.fileName}" onclick="copyFile(this)">
                                                <button class="btn btn-primary file" onclick="download(this)"
                                                        FileSysId="${fileMap.file}">
                                                    下载附件
                                                </button>
                                            </div>
                                        </c:forEach>
                                    </c:if>
                                    <c:if test="${empty taskMain.mainResultFile}">
                                        <input style="width: 50%;" type="text" value="无附件" class=" col-sm-3 form-control" readonly>
                                    </c:if>
                                    &lt;%&ndash;上传&ndash;%&gt;
                                    <div>
                                        <div id="uploader"></div>
                                        &lt;%&ndash;<div style="display: inline-block">&ndash;%&gt;
                                            &lt;%&ndash;<input type="file" class="fileBorder" id="fileuploadZDX">&ndash;%&gt;
                                        &lt;%&ndash;</div>&ndash;%&gt;
                                        &lt;%&ndash;<div style="display: inline-block">&ndash;%&gt;
                                            &lt;%&ndash;<button class="btn btn-info" onclick="uploadFile(this,'mainResultFile','mainResultFileName','fileuploadZDX')">&ndash;%&gt;
                                                &lt;%&ndash;<span class="glyphicon glyphicon-open"></span>上传附件&ndash;%&gt;
                                            &lt;%&ndash;</button>&ndash;%&gt;
                                        &lt;%&ndash;</div>&ndash;%&gt;
                                    </div>
                                    <button class="btn btn-success takefeedbackWd">确认</button>
                                    <button class="btn btn-info " onclick="duchaRank()" >排名</button>
                                </div>
                            </div>
                        </c:when>
                    </c:choose>
                </c:if>
--%>
                <%--<div class="pull-right" style="margin-bottom: 20px;margin-top: 20px;margin-bottom: 10px;">
                    &lt;%&ndash;<button class="btn-sm btn btn-success allTasks">全部任务</button>&ndash;%&gt;
                    <c:if test="${taskMain.taskState == 0}">
                        <button class="btn-success btn btn-sm approval">审批</button>
                    </c:if>
                    <button class="btn-sm btn btn-success addTaskSub">新增子事项</button>
                    <button class="btn-sm btn btn-success addTaskUnitBtn">新增单位</button>
                </div>--%>
                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->
                        <!-- jqGrid表格 -->
                        <table id="gridTable"></table>
                        <!-- jqGrid工具类 -->
                        <div id="gridPager"></div>
                        <!-- 查询对话框 -->
                        <div style="display: none;">
                            <div class="row" id="queryDialog"></div>
                        </div>
                        <!-- PAGE CONTENT ENDS -->
                    </div><!-- /.col -->
                </div><!-- /.row -->
                <h4 class="redTips">温馨提示：双击表格行或者点击"查看" 查看任务详情</h4>
            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->

    <a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
        <i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
    </a>

    <%@ include file="/WEB-INF/views/include/dialog.jsp" %>
</div><!-- /.main-container -->
</div>

<%--多选上传--%>
<script src="<s:url value="/assets/js/dist/easyUploader.jq.js"></s:url>"></script>
<!-- footer -->
<%@ include file="/WEB-INF/views/include/footer.jsp" %>
<%--用于没上传附件时不执行方法--%>
<%--
<input type="text" id="crucialUser" value="${taskMain.crucialUser}" hidden>
--%>
<%--
<input type="text" id="overdueDept" value="${taskMain.overdueDept}" hidden>
--%>

<input type="text" id="sysIds" value="${dept.sysId}" hidden>
<%--
<input type="text" id="categoryId" value="${taskMain.categoryId}" hidden>
--%>

<input type="text" id="deptRelations" value="${dept.deptRelation}" hidden>
<input type="text" id="roleIds" value="${roleId}" hidden>
<script>
    $(function () {
/*
        var a = $("#crucialUser").val();
*/
        var b = $("#sysIds").val();
/*
        var c = $("#categoryId").val();
*/
        var d = $("#deptRelations").val();
/*
        var e = $("#overdueDept").val();
*/
        var f = $("#roleIds").val();
        if (  ( a !== ""&& b !== "20190722100000000194") || (c === "20190919100000000001" && b === e && f === "02")) {
            <%--多文件上传--%>
            var fileStr = "";//id字符串拼接
            var fileNameStr = "";//文件名字符串拼接
            var uploader = easyUploader({
                id: "uploader",
                accept: '.jpg,.png,.doc,.docx,.pdf,.xls,.xlsx,.ppt,.pptx',
                action: '/filesUpload/uploadFiles',
                dataFormat: 'formData',
                maxCount: 10,//允许上传的个数
                maxSize: 2000,//允许上传最大的容量
                multiple: true,
                data: null,
                beforeUpload: function (file, data, args) {
                },
                onChange: function (fileList) {
                },
                onRemove: function (removedFiles, files) {
                    console.log('onRemove', removedFiles);
                },
                onSuccess: function (res) {
                    console.log('onSuccess', res);
                    if (res.data !== undefined && res.data[0] !== undefined) {
                        //拼接文件id 和 文件名
                        $("input[name='file']").val(fileStr += res.data[0].sysid + ",");
                        $("input[name='fileName']").val(fileNameStr += res.data[0].oldName + ",");

                    }
                },
                onError: function (err) {
                    console.log('onError', err);
                },
            });
        }
    })
</script>
<script type="text/javascript">
    // 基本路径
    var baseUrl = "<s:url value="/insideDept/itemTaskLists"></s:url>"

    // jqgrid的表格高度
    var height = 320;
    // jqgrid表格行头的中文
    var colNames = ['','任务单号','子事项名称','周期类型','时限',"承办人", "任务状态","反馈状态"];

    var colModel = [
        {name: 'userTaskId', width: 60,hidden: true, key: true},
        {name: 'sysId', width: 60, width:300 },

        {name: 'subTaskName', index: 'subTaskName', width: 450, editable: true},
        {name: 'timeType', index: 'timeType', width: 300, editable: true,formatter:timeTypeValue},
        {name: 'cycleValue', index: 'cycleValue', width: 300, editable: true},

        {name: 'userName', index: 'userName', width: 200, editable: true,},
        {name: 'taskState', index: 'taskState', width: 100, editable: true,formatter:taskStateValue },
        {name: 'backType', index: 'backType', width: 100, editable: true,  formatter:backTypeValue  },


    ];
    /**
     * 按钮`
     */
    function feedbackBtnFormatter   (value, grid, rows, state) {
        grid.colModel.title=false
        return "<div style='color: #049CE6;display: flex;justify-content: center'>" +
            "<div style='width: 60px;cursor: pointer;border-right:1px solid #049CE6;' title='反馈汇总' id='feedbackBtn1'>反馈汇总</div>" +
            "<div style='width: 40px;cursor: pointer' title='查看' id='feedbackBtn'>查看</div>" +
            "<div style='border-left:1px solid #049CE6;width: 40px;cursor: pointer'title='删除' class='delTask'>删除</div>" +
            "<div style='width: 40px;cursor: pointer;border-left:1px solid #049CE6;' class='urge' title='催办'>催办</div>" +
            "<div style='width: 40px;cursor: pointer;border-left:1px solid #049CE6;' class='modify' title='修改'>修改</div>" +
            "</div>";
    }

    /**
     * 任务时限轮数
     */
      function timeRoundFormatter(data) {
        return "第"+ data + "轮"
    }

    function timeTypeValue(data) {
        switch (data){
            case 1:
                return '单时限';
                break;

            case 2:
                return '天';
                break
            case 3:
                return '周';
                break;
            case 4:
                return '月';
                break;
            case 5:
                return '季';
                break;
            case 6:
                return '多时限';
                break;

            default:
                return '无效设置';
        }
    }

    function taskStateValue(data) {
        switch (data){
            case '0':
                return '未查看';
                break;

            case '3':
                return '逾期';
                break
            case '4':
                return '完成';
                break;

            default:
                return '办理中';
        }
    }

    function backTypeValue(data) {
        switch (data){

            case '1':
                return '有新反馈';
                break;

            default:
                return '无新反馈';
        }
    }


    /**
     * 任务类型格式化
     */
    function categoryIdFormatter(data) {
      switch (data){
          case '1':
              return '牵头';
              break;
          case '2':
              return '协办';
              break;
          default:
              return '未知';
      }
    }

    /**
     * 任务状态格式化
     */
    function typeFormatter(data) {
        switch(data) {
            case '0':
                return '待签收';
                break;
            case '1':
                return '待反馈';
                break;
            case '2':
                return '已反馈';
                break;
            case '3':
                return '退回重办';
                break;
            case '4':
                return '完成';
                break;
            case '5':
                return '已签收';
                break;
            default:
                return '未知';
        }
    }

    /**
     * 逾期天数
     */
    function overdueDayFormatter(data) {
        data = parseInt(data)
        if(data>0){
            return parseInt(data)+"天"
        }else {
            return ""
        }
    }
    /**
     * 附件格式化
     */
    function fileFormatter(data) {
        if (data == null || data == "") {
            return "无任务附件";
        } else {
            return '<input type="button" value="下载" onclick="downDetail(\'' + data + '\')" \n' +
                ' style="width: 100%; height: 32px;" class="btn-large btn-primary"/>';
        }
    }


    // jqgrid的具体执行方法
    var rowIds;
    var userList;
    var type;
    jqgrid({
        gridTableId: "#gridTable",
        gridPagerId: "#gridPager",
        postData:{'taskMainId':$('#taskMainId').html().trim()},
        autoScroll: false,
        shrinkToFit: true,
        multiselect:false,
        rownumbers: true,
        onSelectRow: function (rowid, status) {
            rowIds = rowid
            //选择当前的行
            rowids = rowid
            var selectedRowValue = $("#gridTable").jqGrid('getRowData', rowid);
        },
        ondblClickRow:function (rowid) {
           // alert(rowid);
            console.log(window.parent);
            console.log(window.parent.openapp);
            /**
             * 打开二级页面
             */
            window.parent.openapp("/insideDept/backView/"+rowid,'insidefreeback',"任务详情");
        },

    });


    //点击开二级页面
$(document).on("click","#feedbackBtn1",function(){
        parent.openapp("/taskMain/collect/"+rowIds,rowIds,"反馈汇总");
    });

    $(document).on("click","#feedbackBtn",function(){
        parent.openapp("/taskMain/unitDetail/"+rowIds,rowIds,"任务详情");
    });

    //    催办
    $(document).on("click",".urge",function () {
        $.get("/taskMain/urgeModel/"+rowIds,function (data) {
            userList = data;
            var html = "";
            for (var i = 0; i < data.length;i++){
                if (data[i].name == undefined) {
                    data[i]['name'] = ''
                }
                if(data[i].mobile == undefined) {
                    data[i]['mobile'] = ''
                }
                html += " <div class=\"form-group clearfix\">\n" +
                    "                        <label class=\"control-label col-sm-2 text-right\">姓名</label>\n" +
                    "                        <div class=\"col-sm-9\">\n" +
                    "                            <input type=\"text\" class=\"Modelname form-control\" readonly value='"+data[i].name+"'>\n" +
                    "                        </div>\n" +
                    "                    </div>\n" +
                    "                    <div class=\"form-group clearfix\">\n" +
                    "                        <label class=\"control-label col-sm-2 text-right\">电话</label>\n" +
                    "                        <div class=\"col-sm-9\">\n" +
                    "                            <input type=\"text\" class=\"Modelphone form-control\" readonly value='"+data[i].mobile+"'>\n" +
                    "                        </div>\n" +
                    "                    </div>"
            }

            $(".information").html(html);
        });
        $('#UrgeModel').modal('show'); //显示
    });

    $("#UrgeModel select").change(function () {
        $("#UrgeModel textarea").val( $(this).val());
    })

    $(".UrgeSure").click(function () {
        failure(".UrgeSure",1)
        type = $("input[name='type']:checked").val();
        if (!type){
            type = 0;
        }
        var datas = {
            taskUnitId: rowIds,
            content: $("#UrgeModel textarea").val(),
            userList:userList,
            type:type
        }
        var jsonDatas = JSON.stringify(datas);
        $.ajax({
            url:'/taskMain/saveHasten/',
            type:'POST',
            contentType: 'application/json; charset=UTF-8',
            async:false,
            dataType:'json',
            data:jsonDatas,
            success: function (data) {
                if (data.code == "200") {
                    alert("催办成功");
                    $("#UrgeModel textarea").val("");
                    $("input[name='type']").removeAttr("checked");
                } else {
                    alert("催办失败");
                }
                failure(".UrgeSure",0)
            }
        })
    })






    //审批
    $(document).on("click",".approval",function () {
        var  sysId = $(".taskMain").attr("taskMain")
        $('#approval').modal('show'); //显示
        $.get("/taskMain/approve/"+sysId,function (data) {
            $(".Modelcontent").val(data.content);
            $(".mainName").val(data.mainName);
            $(".sysId").val(data.sysId);

        })
    });
    $(".addApproval").click(function () {
        var datas = {
            status:$("[name='isApproval']:checked").val(),
            content:$(".information1 .content").val(),
            taskMainId:$(".sysId").val()
        }
        if (!datas.status){
            return alert("请选择是否通过 ")
        }
        $.post("/taskMain/approve/",datas,function (data) {
            if (data.code==200) {
                datas.status == 2 ? alert("通过审批") : alert("不通过审批")
                open(location, '_self').close();
            }else {
                alert("审批失败");
            }
        })
    })
    



    //单位反馈
    $(".takefeedbackWd").click(function() {
        failure(".takefeedbackWd",1)
        var datas ={
            mainResult:$("textarea[name='mainResult']").val() ,
            mainResultFile:$("input[name=file]").val(),
            sysId:$(".taskMain").attr("taskMain"),
            mainResultFileName:$("input[name=fileName]").val()
        }
       /* var datas ={
            content:$("textarea[name='mainResult']").val() ,
            file:$("input[name=file]").val(),
            taskMainId:$(".taskMain").attr("taskMain"),
            fileName:$("input[name=fileName]").val()
        }*/
        $.ajax({
           // url:"/taskUnit/saveMainResult",
            url:"/taskUnit/saveDuBanBackInfo",
            type:"post",
            data:datas,
            success:function (data) {
                if(data.code == "200"){
                    alert(data.message);
                    setTimeout(function () {
                        open(location, '_self').close();
                    },50)
                }else if(data.code == "500"){
                    alert(data.message);
                }
                failure(".takefeedbackWd",0)
            }
        })
    })


    /*修改任务*/
    $(document).on("click",".date_picker",function () {
        laydate({
            elem: this,
            min: minDate(),
        });
    });
    $(document).on("click",".modify",function () {
        $.get("/taskMain/getTaskUnit/"+rowIds,function (res) {
            $("input[name=getTimeLimit]").val(res.data.timeLimit)
            $("input[name=sysId]").val(res.data.sysId)
        })
        $("#modify").modal("show")
    })

    /*修改确认*/
    $(".confirmModify").click(function () {
            var datas = {
                timeLimit:$("input[name='getTimeLimit']").val(), //时限
                sysId:$("input[name='sysId']").val()
            }
            console.log(datas)
            $.post("/taskMain/editTaskUnit/",datas,function (data) {
                    if (data.code == 200){
                        alert("修改成功")
                        reload("#gridTable");//重载
                    }else {
                        alert("修改失败");
                    }
            })
    })

    //删除子事项
    $(document).on("click",".delTask",function () {
        if (confirm("是否删除")) {
            $.get("/taskMain/deleteUnit/" + rowIds, function (res) {
                if (res.code == "200") {
                    alert(res.message);
                    setTimeout(function () {
                        open(location, '_self').close();
                    }, 50)
                } else {
                    alert(res.message);
                }
            })
        }
    })
    //新增子事项
    $(".addTaskSub").click(function () {
        var $taskMainSysId = $(".taskMain").attr("taskMain");
        loadDialog({
            dialogTitle: '新增子事项',
            dialogUrl: "/taskMain/addTaskSub/"+$taskMainSysId,
            dialogFoot: '<button type="button" class="btn btn-primary" onclick="create()">添加</button>' +
            '<button type="button" class="btn btn-default" onclick="removeLayDate()" data-dismiss="modal">关闭</button>'
        });
    })

    //新增子事项
    function create() {
        executeSaveOrUpdate({
            formId: "#formDialog form",
            dialogId: "#formDialog",
            url: "/taskMain/addTaskSub/",
            tableId: "#gridTable",
            successMessage: "保存成功",
            successTitle: '保存对话框',
            failMessage: '保存失败',
            failTitle: '消息对话框'
        });
    }

    //新增子事项单位
    $(".addTaskUnitBtn").click(function () {
        var $taskMainSysId = $(".taskMain").attr("taskMain");
        loadDialog({
            dialogTitle: '新增单位',
            dialogUrl: "/taskMain/addTaskUnit/"+$taskMainSysId,
            dialogFoot: '<button type="button" class="btn btn-primary" onclick="createTask()">添加</button>' +
            '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>'
        });
    })

    //新增子事项单位
    function createTask() {
        executeSaveOrUpdate({
            formId: "#formDialog form",
            dialogId: "#formDialog",
            url: "/taskMain/addTaskUnit/",
            tableId: "#gridTable",
            successMessage: "保存成功",
            successTitle: '保存对话框',
            failMessage: '保存失败',
            failTitle: '消息对话框'
        });
    }
    function minDate() {
        var now = new Date();
        return now.getFullYear() + "-" + (now.getMonth() + 1) + "-" + (now.getDate() + 1);
    }
    $(document).ready(function (){
        $(document).on("click","#date_picker",function () {
            laydate({
                elem: "#date_picker",
                min: minDate(),
            });
        });
    })

    //bug 删除时间模态框
    function removeLayDate(){
        $("#laydate_box").remove()
    }


    //任务评价
    function evaluations() {

        var eval  = $("#task-evaluations").val();
        console.log(eval)

        var datas = {
            evaluations:eval, //评价
            sysId:$(".taskMain").attr("taskMain")
        }
        console.log(datas)
        $.post("/taskMain/submitEval",datas,function (data) {
            if (data.code == 200){
                alert("评价成功")
                reload("#gridTable");//重载
            }else {
                alert("修改失败");
            }
        })

    }

    function duchaRank() {
            var eval =$("#task-evaluations").val();//评价
           var  sysId=$(".taskMain").attr("taskMain");
        parent.openapp("/taskMain/dubanfeedback?sysId="+sysId+"&eval="+eval,"接收单位")
    }

</script>

</body>
</html>